package com.ccod.nacos.provider.facade.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ccod.nacos.provider.facade.model.OrderDO;
import com.ccod.nacos.provider.facade.mapper.OrderMapper;
import com.ccod.nacos.order.facade.OrderFacade;
import com.ccod.nacos.order.model.OrderDTO;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author: ccod
 * @data: 2020/12/27 12:24
 **/
@DubboService
public class OrderFacadeImpl implements OrderFacade {

    @Autowired
    private OrderMapper orderMapper;

    public boolean createOrder(OrderDTO dto) {
        if(dto == null){
            System.out.println("参数非法");
            return false;
        }
        OrderDO orderDO = new OrderDO();
        BeanUtils.copyProperties(dto,orderDO);
        return orderMapper.insert(orderDO) > 0;
    }

    public OrderDTO searchOrder(String orderId) {
        OrderDO orderDO = orderMapper.selectOne(new LambdaQueryWrapper<OrderDO>().eq(OrderDO::getOrderId, orderId));
        OrderDTO orderDTO = new OrderDTO();
        BeanUtils.copyProperties(orderDO,orderDTO);
        return orderDTO;
    }

}
